package com.lzx.iteam;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.*;
import android.util.Log;
import android.view.*;
import android.view.inputmethod.InputMethodManager;
import android.widget.*;
import com.lzx.iteam.adapter.VoteAdapter;
import com.lzx.iteam.bean.EventListData;
import com.lzx.iteam.widget.gridimg.AllEasyGridView;
import com.lzx.iteam.widget.gridimg.EasyGridView;
import com.lzx.iteam.widget.gridimg.ImageAdapter;
import com.lzx.iteam.net.AsynHttpClient;
import com.lzx.iteam.net.CreateEventMsg;
import com.lzx.iteam.net.GetQnTokenMsg;
import com.lzx.iteam.net.LocalLogin;
import com.lzx.iteam.provider.CloudDBOperation;
import com.lzx.iteam.provider.EventsMsgDB;
import com.lzx.iteam.widget.selectdate.OnWheelScrollListener;
import com.lzx.iteam.widget.selectdate.WheelView;
import com.lzx.iteam.widget.selectdate.adapter.NumericWheelAdapter;
import com.lzx.iteam.selectimage.Bimp;
import com.lzx.iteam.selectimage.Res;
import com.lzx.iteam.util.*;
import com.lzx.iteam.widget.MyListView;
import io.rong.imageloader.core.ImageLoader;
import com.qiniu.android.http.ResponseInfo;
import com.qiniu.android.storage.UpCompletionHandler;
import com.lzx.iteam.widget.kpswitch.util.KPSwitchConflictUtil;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.*;

/**
 * Created by shijunting on 15-5-20.
 */
public class CreateNewEventActivity extends Activity implements View.OnClickListener, EasyGridView.IHandleGridView, VoteAdapter.OnUpdateLinster {

    private TextView mCreateEventCancle, mCreateEventOk, mCreateEventReceiverName, mCreateEventContentTitle;
    private ImageView mCreateEventAddReceiver, mCreateEventAddReceiverArrow;
    private EditText mCreateEventTheme, mCreateEventContent;
    private EditText mEventPart1;
    private EditText mEventAuthor;
    private EditText mEventAddress;
    private TextView mTvEventTime;
    private TextView mTvTitle;
    private TextView mTvNoticeTitle;
    private TextView mTvNote;
    private View mViewPart1;
    private RelativeLayout mCreateEventTitle, mEventReceiverLayout;
    private RelativeLayout mRlEventTitle, mRlEventReceiver;
    private RelativeLayout mRlEventAuthor;
    private RelativeLayout mRlEventActiviteTime, mRlEventActiviteAddress;
    private RelativeLayout mRlEndTime, mRlOpenQrcode;
    private LinearLayout mLayoutPart1;
    private ScrollView mCreateEventLayout;
    private AllEasyGridView mEventReceiverGrid;
    private LinearLayout mEventReceiverBack, mLayoutHelp;
    private String mEventId;
    private String mEventTheme;
    private String mEventName;
    private String mReceiverMsg = "";
    private String mEventAvatar;
    private String mHintPart1, mPart1;
    private String mFilePath;

    private ImageView mSelectIv, mIvTakePhoto;
    private HorizontalScrollView mImageHScrollView;
    private LinearLayout mImageHLinearLayout;
    private LinearLayout mShowImageLayout;

    private CreateNewEventActivity mActivity;
    private PreferenceUtil mPreferenceUtil;
    private Dialog mWaitDialog;
    private CloudDBOperation mCloudDBOperation;
    private EventsMsgDB mEventDB;
    private ImageAdapter adapter;
    private PopupWindow mMoreWindow;
    private String mEventType;
    private String mEventActiviteTime;
    private String mEventEndTime;
    private String isQrcode = "1";
    private String mEventActiviteAddress;
    private String mAuthor;
    private Bitmap mBitMap;
    private JSONArray imageArray;
    private List<Map<String, byte[]>> keyByte = new ArrayList<Map<String, byte[]>>();
    private String images;

    private WheelView year;
    private WheelView month;
    private WheelView day;
    private WheelView hour;
    private WheelView mins;
    private TextView years;
    private int mStartYear, mEndYear;
    private int mStartMonth, mEndMonth;
    private int mStartDay, mEndDay;
    private int mStartHour, mEndHour;
    private int mStartMinute, mEndMinute;
    private int curYear;
    private int curMonth;
    private int curDate;
    private int curHour;
    private int curMinute;
    private long mStartTime;
    private long mEndTime;

    // 投票部分
    private MyListView mVoteList;
    private VoteAdapter mVoteAdapter;
    private ArrayList<String> mVoteData;
    private String mPassVoteData;
    private RelativeLayout mRlMoreVoteNumber;
    private TextView mTvVoteNumber;
    public  int mMaxVoteNumber = 1; // 投票数目
    private static final int VOTE_NUMBER = 10001;

    // 签到部分
    private TextView mTvCreateEventTime;
    private TextView mTvEndTime;
    private TextView mTvCreateEventAddress;
    private LinearLayout mLlCreateEventImage;
    private ToggleButton mTbQrcode;


    private PopupWindow mDateSelectPop;
    private PopupWindow mTimeContinuePop;
    private Calendar c;
    private int mImageCount;
    private static final int GET_QN_TOKEN = 1000;
    private static final int CREATE_NEW_EVENT = 1001;
    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);
            switch (msg.what) {
                case CREATE_NEW_EVENT://新建事件
                    httpReqDlgDismiss();
                    if (msg.arg1 == 0) {
                        EventListData eventData = (EventListData) msg.obj;
                        if ("8".equals(mEventType)){
                            eventData.setVoteMaxNumber(mMaxVoteNumber+"");
                        }
                        // TODO 记录新创建的eventId；
                        Constants.NEW_EVENT_ID = eventData.getEventId();
                        mPreferenceUtil.save("event_count", (Integer.parseInt(mPreferenceUtil.getString("event_count", "0")) + 1) + "");
                        mCloudDBOperation.insertEvent(eventData);
                        Intent toMain = new Intent(CreateNewEventActivity.this, MainActivity.class);
                        toMain.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                        startActivity(toMain);

                        if (!StringUtil.isEmpty(mEventId)) {
                            mCloudDBOperation.deleteEventDraftsByEventId(mEventId);
                        }
                        if (Bimp.mPictureData.size() > 0) {
                            Bimp.mPictureData.clear();
                        }
                        // TODO 把图片存放在备份list中，以便创建完成后先加载本地图片
                        for (String data : Bimp.tempSelectBitmap) {
                            Bimp.mPictureData.add(data);
                        }
                        Bimp.tempSelectBitmap.clear();
                        finish();
                    } else {
                        if (msg.arg1 == AsynHttpClient.ERROR_LOCAL) {
                            Toast.makeText(CreateNewEventActivity.this, R.string.active_failure_no_network,
                                    Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(CreateNewEventActivity.this, (String) msg.obj, Toast.LENGTH_LONG).show();
                        }
                    }
                    break;
                case GET_QN_TOKEN:
                    if (msg.arg1 == 0) {
                        Map<String, Object> map = (HashMap<String, Object>) msg.obj;
                        for (int i = 0; i < keyByte.size(); i++) {
                            Map<String, byte[]> map1 = keyByte.get(i);
                            for (String key : map1.keySet()) {
                                setPhoto((String) map.get(key), map1.get(key), key);
                            }

                        }
                    }
                    break;

            }
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.create_event_layout);
        mActivity = this;
        mPreferenceUtil = PreferenceUtil.getInstance(this);
        mCloudDBOperation = new CloudDBOperation(this);
        mEventDB = new EventsMsgDB(this);
        c = Calendar.getInstance();
        curYear = c.get(Calendar.YEAR);
        curMonth = c.get(Calendar.MONTH) + 1; //通过Calendar算出的月数要+1
        curDate = c.get(Calendar.DATE);
        curHour = c.get(Calendar.HOUR_OF_DAY);
        curMinute = c.get(Calendar.MINUTE);
        initView();
        Res.init(this);
        getIntentData();
    }


    @Override
    protected void onResume() {
        super.onResume();
        setImageMsg();
        if (mCreateEventReceiverName.getText().toString().length() > 0) {
            mCreateEventAddReceiverArrow.setVisibility(View.VISIBLE);
            mCreateEventAddReceiver.setVisibility(View.GONE);
            if (mCreateEventTheme.getText().toString().length() > 0) {
                Message message = mHandler.obtainMessage(0);
                message.sendToTarget();
            }
        } else {
            mCreateEventAddReceiverArrow.setVisibility(View.GONE);
            mCreateEventAddReceiver.setVisibility(View.VISIBLE);
        }
        Log.d("InstanceState", "-- onResume  ==  ");

    }


    private void initView() {
        mCreateEventTitle = (RelativeLayout) findViewById(R.id.rl_create_event_title);
        mEventReceiverLayout = (RelativeLayout) findViewById(R.id.event_receiver_layout);
        mCreateEventLayout = (ScrollView) findViewById(R.id.sv_create_event);
        mCreateEventCancle = (TextView) findViewById(R.id.create_event_cancle);
        mCreateEventOk = (TextView) findViewById(R.id.create_event_ok);
        mCreateEventReceiverName = (TextView) findViewById(R.id.tv_create_event_receiver_name);
        mCreateEventTheme = (EditText) findViewById(R.id.tv_create_event_theme_name);
        mCreateEventContentTitle = (TextView) findViewById(R.id.tv_create_event_content);
        mCreateEventContent = (EditText) findViewById(R.id.tv_create_event_content_name);
        mCreateEventAddReceiver = (ImageView) findViewById(R.id.iv_create_event_receiver_add);
        mCreateEventAddReceiverArrow = (ImageView) findViewById(R.id.iv_create_event_receiver_add_arrow);
        mEventReceiverBack = (LinearLayout) findViewById(R.id.event_receiver_back);
        mEventReceiverGrid = (AllEasyGridView) findViewById(R.id.aegv_event_receiver);
        mRlEventTitle = (RelativeLayout) findViewById(R.id.rl_event_title);
        mRlEventReceiver = (RelativeLayout) findViewById(R.id.rl_create_event_receiver);
        mRlEventAuthor = (RelativeLayout) findViewById(R.id.rl_event_public_title);
        mTvNoticeTitle = (TextView) findViewById(R.id.tv_create_event_theme);
        mEventAuthor = (EditText) findViewById(R.id.tv_create_event_public_theme_name);
        mRlEventReceiver.setOnClickListener(this);
        mCreateEventContentTitle.setOnClickListener(this);
        mEventReceiverBack.setOnClickListener(this);
        mCreateEventCancle.setOnClickListener(this);
        mCreateEventOk.setOnClickListener(this);
        mCreateEventAddReceiver.setOnClickListener(this);
        mTvNote = (TextView) findViewById(R.id.create_event_tv_note);
        mLayoutHelp = (LinearLayout) findViewById(R.id.event_ll_help);
        mLayoutHelp.setOnClickListener(this);

        mEventPart1 = (EditText) findViewById(R.id.et_event_part1);
        mLayoutPart1 = (LinearLayout) findViewById(R.id.ll_event_part1);
        mTvTitle = (TextView) findViewById(R.id.create_event_title);
        mViewPart1 = findViewById(R.id.view_event_part1);

        // 活动
        mRlEventActiviteTime = (RelativeLayout) findViewById(R.id.rl_create_event_active_time);
        mRlEventActiviteAddress = (RelativeLayout) findViewById(R.id.rl_event_active_layout);
        mTvEventTime = (TextView) findViewById(R.id.tv_create_event_active_time);
        mEventAddress = (EditText) findViewById(R.id.tv_create_event_active_address);
        mRlEventActiviteTime.setOnClickListener(this);

        // 投票
        mVoteList = (MyListView) findViewById(R.id.creat_vote_list);
        mSelectIv = (ImageView) findViewById(R.id.create_event_iv_select);
        mSelectIv.setOnClickListener(this);
        mIvTakePhoto = (ImageView) findViewById(R.id.create_event_iv_photo);
        mIvTakePhoto.setOnClickListener(this);
        mImageHScrollView = (HorizontalScrollView) this.findViewById(R.id.create_event_h_scrollview);
        mImageHLinearLayout = (LinearLayout) this.findViewById(R.id.create_event_h_gallery);
        mShowImageLayout = (LinearLayout) findViewById(R.id.create_add_image_layout);
        mRlMoreVoteNumber = (RelativeLayout) findViewById(R.id.rl_create_event_vote_more);
        mTvVoteNumber = (TextView) findViewById(R.id.tv_create_event_vote_num);
        mRlMoreVoteNumber.setOnClickListener(this);

        // 签到部分
        mRlEndTime = (RelativeLayout) findViewById(R.id.rl_create_event_active_endtime);
        mRlOpenQrcode = (RelativeLayout) findViewById(R.id.rl_event_qrcode_notice);
        mRlEndTime.setOnClickListener(this);
        mRlOpenQrcode.setOnClickListener(this);
        mTvCreateEventTime = (TextView) findViewById(R.id.tv_event_active_time);
        mTvCreateEventAddress = (TextView) findViewById(R.id.tv_active_address);
        mLlCreateEventImage = (LinearLayout) findViewById(R.id.event_ll_image_select);
        mTvEndTime = (TextView) findViewById(R.id.tv_create_event_active_endtime);
        mTbQrcode = (ToggleButton) findViewById(R.id.tb_qrcode_notice);
        mTbQrcode.setChecked(true);

    }

    private void setNotice(String notice) {
        if ("0".equals(notice)) {
            mTbQrcode.setChecked(false);
        } else if ("1".equals(notice)) {
            mTbQrcode.setChecked(true);
        }
    }

    private String getNotice() {//1:显示电话号码(默认),0:隐藏电话号码
        if (mTbQrcode.isChecked()) {
            return "1";
        } else {
            return "0";
        }
    }

    private void getIntentData() {

        mEventAvatar = mPreferenceUtil.getString(PreferenceUtil.NAMECARD_AVATAR, "");
        Intent intent = getIntent();
        if (intent.getBundleExtra("event_msg") != null) {
            Bundle bundle = intent.getBundleExtra("event_msg");
            EventListData eventData = (EventListData) bundle.getSerializable("event_bundle");

            mEventId = eventData.getEventId();
            mEventType = eventData.getEventType();
            mEventName = eventData.getEventName();
            mReceiverMsg = eventData.getReceiver();
            mEventTheme = eventData.getEventTitle();
            mPart1 = eventData.getContent1();
            mHintPart1 = eventData.getInitTitle1();
            mPassVoteData = eventData.getContent1();
            if (!StringUtil.isEmpty(eventData.getVoteMaxNumber())){
                mMaxVoteNumber = Integer.parseInt(eventData.getVoteMaxNumber());
            }else{
                mMaxVoteNumber = 1;
            }
            images = eventData.getThumbImage();
            if (!StringUtil.isEmpty(images)) {
                for (String image : images.split(",")) {
                    Bimp.tempSelectBitmap.add(image);
                }
            }
            String time = eventData.getActivityTime();
            String endTime = eventData.getEndTime();
            String qrcode = eventData.getIsQrcode();

            if (!StringUtil.isEmpty(time) && !"0".equals(time)) {
                mStartTime = Long.parseLong(time);
                mEventActiviteTime = DateUtil.getAllTime(mStartTime);
                mStartMonth = DateUtil.getMonth(mStartTime);
                mStartDay = DateUtil.getDay(mStartTime);
            }
            if (!StringUtil.isEmpty(endTime)) {
                mEndTime = Long.parseLong(endTime);
                mEndHour = DateUtil.getHour(mEndTime);
                mEndMinute = DateUtil.getMinute(mEndTime);
                if (mEndHour != 0 && mEndMinute != 0) {
                    mEventEndTime = DateUtil.getHourAndMin(mEndTime);
                }
            }
            if (!StringUtil.isEmpty(qrcode)) {
                isQrcode = qrcode;
            }
            mEventActiviteAddress = eventData.getActivitySite();
            mAuthor = eventData.getAuthor();

            ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
            StringBuilder sb = new StringBuilder();
            try {
                JSONArray jsonArray = new JSONArray(mReceiverMsg);
                for (int i = 0; i < jsonArray.length(); i++) {
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    sb.append(jsonObject.get("user_name") + ",");
                    map.put("text", jsonObject.get("user_name"));
                    map.put("user_id", jsonObject.getString("user_id"));
                    map.put("icon", jsonObject.get("user_image").toString());
                    map.put("contact_id", jsonObject.get("contact_id"));
                    list.add(map);
                }
                mCreateEventReceiverName.setText(sb.substring(0, sb.length() - 1));
                if (mCreateEventReceiverName.getText().toString().trim().length() > 0) {
                    Message message = mHandler.obtainMessage(0);
                    message.sendToTarget();
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            mTvTitle.setText(mEventName);
            if (!StringUtil.isEmpty(mEventTheme)) {
                mRlEventTitle.setVisibility(View.VISIBLE);
                mCreateEventTheme.setText(mEventTheme);
            } else if (mEventType.equals("4")) {
                mRlEventTitle.setVisibility(View.VISIBLE);
                mCreateEventTheme.setText("");
            }

            if (mEventType.equals("1")) { // 公告
                mTvNote.setText(getString(R.string.event_an));
                mRlEventTitle.setVisibility(View.VISIBLE);
                mTvNoticeTitle.setText("公告标题: ");
                mRlEventAuthor.setVisibility(View.VISIBLE);
                if (!StringUtil.isEmpty(mAuthor)) {
                    mEventAuthor.setText(mAuthor);
                }
                mLayoutPart1.setVisibility(View.VISIBLE);
                mViewPart1.setVisibility(View.GONE);
                if (!StringUtil.isEmpty(mPart1)) {
                    mEventPart1.setText(mPart1);
                } else {
                    mEventPart1.setHint("公告内容");
                }

            } else if (mEventType.equals("7")) { // 活动
                mTvNote.setText(getString(R.string.event_active));
                mRlEventTitle.setVisibility(View.VISIBLE);
                mTvNoticeTitle.setText("活动主题: ");
                mRlEventActiviteTime.setVisibility(View.VISIBLE);
                mRlEventActiviteAddress.setVisibility(View.VISIBLE);
                if (!StringUtil.isEmpty(mAuthor)) {
                    mEventAuthor.setText(mAuthor);
                }
                if (!StringUtil.isEmpty(mEventActiviteTime)) {
                    mTvEventTime.setText(mEventActiviteTime);
                }
                if (!StringUtil.isEmpty(mEventActiviteAddress)) {
                    mEventAddress.setText(mEventActiviteAddress);
                }

                mLayoutPart1.setVisibility(View.VISIBLE);
                mViewPart1.setVisibility(View.GONE);
                if (!StringUtil.isEmpty(mPart1)) {
                    mEventPart1.setText(mPart1);
                } else {
                    mEventPart1.setHint("活动内容");
                }

            } else if (mEventType.equals("8")) { //投票
                mTvNote.setText(getString(R.string.event_vote));
                mTvVoteNumber.setText("最多选" + mMaxVoteNumber + "项");
                mRlEventTitle.setVisibility(View.VISIBLE);
                mRlMoreVoteNumber.setVisibility(View.VISIBLE);
                mTvNoticeTitle.setText("投票标题: ");
                mVoteList.setVisibility(View.VISIBLE);
                mVoteData = new ArrayList<String>();
                if (StringUtil.isEmpty(mPassVoteData) || ",".equals(mPassVoteData)) {
                    mVoteData.add("");
                    mVoteData.add("");
                } else {
                    String[] votes = mPassVoteData.split(",", -1);
                    for (int i = 0; i < votes.length; i++) {
                        mVoteData.add(votes[i]);
                    }
                }
                mVoteAdapter = new VoteAdapter(mVoteData, this);
                mVoteAdapter.setOnUpdateLinster(this);
                mVoteList.setAdapter(mVoteAdapter);


            } else if (mEventType.equals("9")) {
                mTvNote.setText(getString(R.string.event_reg));
                mTvNoticeTitle.setText("签到主题: ");
                mTvCreateEventTime.setText("签到时间: ");
                mTvCreateEventAddress.setText("地点: ");
                mLlCreateEventImage.setVisibility(View.GONE);
                mRlEventActiviteTime.setVisibility(View.VISIBLE);
                mRlEventActiviteAddress.setVisibility(View.VISIBLE);
                mRlEndTime.setVisibility(View.VISIBLE);
                mRlOpenQrcode.setVisibility(View.VISIBLE);

                if (!StringUtil.isEmpty(mEventActiviteTime)) {
                    mTvEventTime.setText(mEventActiviteTime);
                }
                if (!StringUtil.isEmpty(mEventEndTime)) {
                    mTvEndTime.setText(mEventEndTime);
                }
                setNotice(isQrcode);
                if (!StringUtil.isEmpty(mEventActiviteAddress)) {
                    mEventAddress.setText(mEventActiviteAddress);
                }

                mLayoutPart1.setVisibility(View.VISIBLE);
                mViewPart1.setVisibility(View.GONE);
                if (!StringUtil.isEmpty(mPart1)) {
                    mEventPart1.setText(mPart1);
                } else {
                    mEventPart1.setHint("备注");
                }

            } else {
                mTvNote.setText(getString(R.string.event_normal));
                mLayoutPart1.setVisibility(View.VISIBLE);
                mEventPart1.setMinLines(6);
                mViewPart1.setVisibility(View.GONE);
                if (!StringUtil.isEmpty(mPart1)) {
                    mEventPart1.setText(mPart1);
                } else if (!StringUtil.isEmpty(mHintPart1)) {
                    mEventPart1.setHint("请填写" + mHintPart1);
                } else {
                    mEventPart1.setHint("请填写内容");
                }
            }


            adapter = new ImageAdapter(CreateNewEventActivity.this, true);
            mEventReceiverGrid.initData(false, list, adapter);
            mEventReceiverGrid.setHandleGridView(CreateNewEventActivity.this);

        }

    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.create_event_cancle:
                if (mCreateEventReceiverName.getText().toString().length() > 0 || mCreateEventTheme.getText().toString().length() > 0 || mEventPart1.getText().toString().length() > 0 || mTvEventTime.getText().toString().length() > 0 || mEventAddress.getText().toString().length() > 0 || mEventAuthor.getText().toString().length() > 0 || Bimp.tempSelectBitmap.size() > 0) {
                    StringBuilder stringBuilder = new StringBuilder();
                    if (Bimp.tempSelectBitmap != null && Bimp.tempSelectBitmap.size() > 0) {
                        for (String image : Bimp.tempSelectBitmap) {
                            stringBuilder.append(image + ",");
                        }
                        images = stringBuilder.toString();
                    } else {
                        images = "";
                    }
                    showSavePop();
                } else {
                    finish();
                }
                try {
                    ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(CreateNewEventActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                Bimp.deleteAllPhoto();
                break;
            case R.id.create_event_ok:

                if (mCreateEventReceiverName.getText().toString().length() == 0) {
                    Toast.makeText(CreateNewEventActivity.this, "对不起，您至少要选择一位收件人", Toast.LENGTH_SHORT).show();
                    return;
                }
                if (StringUtil.isEmpty(mCreateEventTheme.getText().toString())) {
                    Toast.makeText(CreateNewEventActivity.this, "对不起，主题不能为空", Toast.LENGTH_SHORT).show();
                    return;
                }

                if (mEventType.equals("7") || mEventType.equals("9")) {
                    if (StringUtil.isEmpty(mEventActiviteTime)) {
                        Toast.makeText(CreateNewEventActivity.this, "对不起，时间不能不能为空", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    if (mStartTime < System.currentTimeMillis()) {
                        Toast.makeText(CreateNewEventActivity.this, "对不起，时间已经过时", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    if (mEventType.equals("9")){

                        if (mEndTime == 0){
                            Toast.makeText(CreateNewEventActivity.this, "对不起，结束时间不能不能为空", Toast.LENGTH_SHORT).show();
                            return;
                        }
                        if (mEndTime < mStartTime) {
                            Toast.makeText(CreateNewEventActivity.this, "结束时间小于签到时间，请重新选择", Toast.LENGTH_SHORT).show();
                            return;
                        }

                    }

                    /*if (mEndTime == 0 && mEventType.equals("9")) {
                        Toast.makeText(CreateNewEventActivity.this, "对不起，结束时间不能不能为空", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    c.set(curYear, mStartMonth - 1, mStartDay, mEndHour, mEndMinute, 00);
                    mEndTime = c.getTimeInMillis();
                    if (mEndHour != 0 && mEndMinute != 0 && mEndTime < mStartTime) {
                        Toast.makeText(CreateNewEventActivity.this, "结束时间小于签到时间，请重新选择", Toast.LENGTH_SHORT).show();
                        return;
                    }*/

                    if (StringUtil.isEmpty(mEventAddress.getText().toString())) {
                        Toast.makeText(CreateNewEventActivity.this, "对不起，地点不能不能为空", Toast.LENGTH_SHORT).show();
                        return;
                    }
                }
                if (!mEventType.equals("8") && !mEventType.equals("9")) {
                    if (StringUtil.isEmpty(mEventPart1.getText().toString().trim())) {
                        Toast.makeText(CreateNewEventActivity.this, "对不起，内容不能为空", Toast.LENGTH_SHORT).show();
                        return;
                    }
                }

                ArrayList<String> data = new ArrayList<String>();
                if (mEventType.equals("8")){
                    mPassVoteData = getPassVoteData();
                    String[] votes = mPassVoteData.split(",");
                    for (int i = 0; i < votes.length; i++) {
                        if (!StringUtil.isEmpty(votes[i])) {
                            data.add(votes[i]);
                        }
                    }
                    if (data.size() < 2) {
                        Toast.makeText(this, "至少填写两项", Toast.LENGTH_SHORT).show();
                        return;
                    }
                }

                httpReqDlgShow();
                if (Bimp.tempSelectBitmap.size() > 0) {
                    imageArray = new JSONArray();
                    StringBuilder stringBuilder = new StringBuilder();
                    for (String image : Bimp.tempSelectBitmap) {
                        Map<String, byte[]> token = new HashMap<String, byte[]>();
                        String key = UUID.randomUUID().toString() + System.currentTimeMillis();
                        if (mBitMap != null) {
                            if (!mBitMap.isRecycled()) {
                                mBitMap.recycle();
                            }
                            mBitMap = null;
                        }
                        mBitMap = PhotoUtil.readBitmapFromPath(CreateNewEventActivity.this, image, true);
                        if (mBitMap != null && !mBitMap.isRecycled()) {
                            byte[] bytes = PhotoUtil.compressImage(mBitMap);
                            token.put(key, bytes);
                        }
                        stringBuilder.append(key + ",");
                        keyByte.add(token);
                        try {
                            JSONObject jsonObject = new JSONObject();
                            jsonObject.put("type", "1");
                            jsonObject.put("data", key);
                            imageArray.put(jsonObject);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                    }
                    getQnToken(stringBuilder.substring(0, stringBuilder.length() - 1));

                }
                if (mEventType.equals("7")) { // 活动
                    createNewActive();
                } else if (mEventType.equals("8")) {
                    createNewVote(data);
                } else if (mEventType.equals("9")) {
                    createNewReg();
                } else {
                    createNewEvent();
                }

                break;
            case R.id.iv_create_event_receiver_add:
                ((DialerApp) getApplication()).setmEventToWhere("1");
                Intent intent1 = new Intent(CreateNewEventActivity.this, ChooseContactByTeamActivity.class);
                intent1.setAction("events_add_receiver");
                Bundle bundle = new Bundle();
                EventListData eventData = new EventListData();
                eventData.setEventType(mEventType);
                eventData.setEventName(mTvTitle.getText().toString().trim());
                if (mReceiverMsg == null) {
                    eventData.setReceiver("");
                } else {
                    eventData.setReceiver(mReceiverMsg);
                }
                eventData.setEventTitle(mCreateEventTheme.getText().toString().trim());
                eventData.setContent1(mEventPart1.getText().toString().trim());
                eventData.setContent2(mEventPart1.getText().toString().trim());
                eventData.setContent3(mEventPart1.getText().toString().trim());
                eventData.setInitTitle1(mHintPart1);
                eventData.setAuthor(mEventAuthor.getText().toString().trim());
                eventData.setActivityTime(mStartTime + "");
                eventData.setVoteMaxNumber(mMaxVoteNumber + "");

                c.set(curYear, mStartMonth - 1, mStartDay, mEndHour, mEndMinute, 00);
                mEndTime = c.getTimeInMillis();
                eventData.setEndTime(mEndTime + "");

                eventData.setIsQrcode(getNotice());
                eventData.setActivitySite(mEventAddress.getText().toString());
                if (mEventType.equals("8")) {
                    eventData.setContent1(getPassVoteData());
                }
                bundle.putSerializable("event_bundle", eventData);
                intent1.putExtra("event_msg", bundle);
                startActivity(intent1);
                break;
            case R.id.create_event_iv_select:
                Intent intent2 = new Intent(this, ImageFileActivity.class);
                startActivity(intent2);
                break;
            case R.id.create_event_iv_photo:
                mFilePath = PhotoUtil.doTakePhotoEvent(this);
                break;
            case R.id.rl_create_event_receiver:
                try {
                    ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (mCreateEventReceiverName.getText().toString().length() > 0) {
                    mCreateEventTitle.setVisibility(View.GONE);
                    mEventReceiverLayout.setVisibility(View.VISIBLE);
                    mCreateEventLayout.setVisibility(View.GONE);
                    mShowImageLayout.setVisibility(View.GONE);
                }
                break;
            case R.id.event_receiver_back:
                mCreateEventTitle.setVisibility(View.VISIBLE);
                mEventReceiverLayout.setVisibility(View.GONE);
                mCreateEventLayout.setVisibility(View.VISIBLE);
                mShowImageLayout.setVisibility(View.VISIBLE);
                break;
            case R.id.tv_create_event_content:
                mCreateEventContent.requestFocus();
                InputMethodManager imm = (InputMethodManager) mCreateEventContent.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
                break;
            case R.id.rl_create_event_active_time:
                try {
                    ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(CreateNewEventActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                showDateSelectPop();
                break;
            case R.id.rl_create_event_active_endtime:
                try {
                    ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(CreateNewEventActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                if (mStartTime == 0) {
                    Toast.makeText(mActivity, "请先选择签到时间", Toast.LENGTH_SHORT).show();
                } else {
                    showContinueDateSelectPop();
                }
                break;
            case R.id.rl_event_qrcode_notice:
                mTbQrcode.toggle();
                break;
            case R.id.event_ll_help:
                Intent intent = new Intent(mActivity, WebViewActivity.class);
                //1：公告，2：审批，3：周报，4：普通事件，5：自定义  6:系统通知  7：活动 8：投票 9:会议通知（签到）
                String title = "";
                int type = 0;
                if ("4".equals(mEventType)) {
                    title = "如何发布事件?";
                    type = 9;
                } else if ("1".equals(mEventType)) {
                    title = "如何发布公告?";
                    type = 6;
                } else if ("7".equals(mEventType)) {
                    title = "如何发布活动?";
                    type = 6;
                } else if ("8".equals(mEventType)) {
                    title = "如何发布投票?";
                    type = 7;
                } else if ("9".equals(mEventType)) {
                    title = "如何发布会议通知?";
                    type = 8;
                }
                intent.putExtra("title", title);
                intent.putExtra("type", type);
                startActivity(intent);
                break;
            case R.id.rl_create_event_vote_more:
                Intent voteNum = new Intent(mActivity,EventVoteNumActivity.class);
                voteNum.putExtra("number",mMaxVoteNumber);
                startActivityForResult(voteNum,VOTE_NUMBER);
                break;
        }
    }

    /**
     * 保存草稿箱提示
     */
    private void showSavePop() {
        View mainView = LayoutInflater.from(this).inflate(R.layout.event_save_pop_layout, null);
        Button yes = (Button) mainView.findViewById(R.id.event_save_yes);
        yes.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                EventListData bean = new EventListData();
                bean.setUserId(mPreferenceUtil.getString(PreferenceUtil.CLIENT_USEID, ""));
                bean.setEventType(mEventType);
                bean.setEventName(mTvTitle.getText().toString());
                bean.setReceiver(mReceiverMsg);
                bean.setEventTitle(mCreateEventTheme.getText().toString().trim());
                // 草稿的eventId  和 发送时间暂时先用系统时间
                bean.setEventId(System.currentTimeMillis() + "");
                bean.setUpdateTime(System.currentTimeMillis() + "");
                bean.setVoteMaxNumber(mMaxVoteNumber + "");
                if (mEventType.equals("8")) {
                    bean.setContent1(getPassVoteData());
                } else {
                    bean.setInitTitle1(mHintPart1);
                    bean.setContent1(mEventPart1.getText().toString().trim());
                }
                bean.setAuthor(mEventAuthor.getText().toString().trim());
                bean.setActivityTime("" + mStartTime);
                if (mEventType.equals("9")) {
                    c.set(curYear, mStartMonth - 1, mStartDay, mEndHour, mEndMinute, 00);
                    mEndTime = c.getTimeInMillis();
                    bean.setEndTime("" + mEndTime);
                    bean.setIsQrcode(getNotice());
                }
                bean.setThumbImage(images);
                bean.setActivitySite(mEventAddress.getText().toString().trim());
                if (!StringUtil.isEmpty(mEventId) && mCloudDBOperation.queryEventDraftsById(mEventId)) {
                    mCloudDBOperation.updataEventDrafts(mEventId, bean);
                } else {
                    mCloudDBOperation.insertEventDrafts(bean);
                }
                int unRead = mPreferenceUtil.getInt(DraftsActivity.DRAFT_EVENT_UNREAD, 0);
                mPreferenceUtil.save(DraftsActivity.DRAFT_EVENT_UNREAD, unRead + 1);

                mMoreWindow.dismiss();
                Toast.makeText(CreateNewEventActivity.this, "草稿保存成功", Toast.LENGTH_SHORT).show();
                Bimp.tempSelectBitmap.clear();
                finish();

            }
        });

        Button no = (Button) mainView.findViewById(R.id.event_save_no);
        no.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mMoreWindow.dismiss();
                mPreferenceUtil.save(DraftsActivity.DRAFT_EVENT_ID, "");
                Bimp.deleteAllPhoto();
                finish();
            }
        });

        Button cancel = (Button) mainView.findViewById(R.id.event_save_cancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mMoreWindow.dismiss();
            }
        });

        mMoreWindow = new PopupWindow(this);
        mMoreWindow.setBackgroundDrawable(new BitmapDrawable());
        mMoreWindow.setFocusable(true);
        mMoreWindow.setTouchable(true);
        mMoreWindow.setOutsideTouchable(true);
        mMoreWindow.setContentView(mainView);
        mMoreWindow.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        mMoreWindow.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        mMoreWindow.setAnimationStyle(R.style.bottomStyle);
        mMoreWindow.showAtLocation(mainView, Gravity.BOTTOM, 0, 0);
        mMoreWindow.update();

        mainView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                mMoreWindow.dismiss();
                return false;
            }
        });

    }

    /**
     * 选择日期时间 pop
     */
    public void showDateSelectPop() {

        final View view = LayoutInflater.from(this).inflate(R.layout.select_date_pop_layout, null);

        year = (WheelView) view.findViewById(R.id.new_year);
        initYear(curYear);
        month = (WheelView) view.findViewById(R.id.new_month);
        initMonth();
        day = (WheelView) view.findViewById(R.id.new_day);
        initDay(curYear, curMonth);
        if (mStartYear != 0){
            year.setCurrentItem(mStartYear - curYear);
        }else{
            year.setCurrentItem(0);
        }
        if (mStartMonth != 0) {
            month.setCurrentItem(mStartMonth - 1);
        } else {
            month.setCurrentItem(curMonth - 1);
        }
        if (mStartDay != 0) {
            day.setCurrentItem(mStartDay - 1);
        } else {
            day.setCurrentItem(curDate - 1);
        }

        hour = (WheelView) view.findViewById(R.id.new_hour);
        initHour();
        mins = (WheelView) view.findViewById(R.id.new_mins);
        initMins();
        // 设置当前时间
        if (mStartHour != 0) {
            hour.setCurrentItem(mStartHour);
        } else {
            hour.setCurrentItem(curHour);
        }

        int current = 0;
        if (mStartMinute != 0) {
            current = mStartMinute / 5;
        } else {
            current = curMinute / 5;
        }
        if (current == 11) {
            mins.setCurrentItem(0);
        } else {
            mins.setCurrentItem(current + 1);
        }

        TextView bt = (TextView) view.findViewById(R.id.new_set);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mStartYear = year.getCurrentItem() + curYear;
                mStartMonth = month.getCurrentItem() + 1;
                mStartDay = day.getCurrentItem() + 1;
                mStartHour = hour.getCurrentItem();
                mStartMinute = mins.getCurrentItem() * 5;

                if (isOverTime()) {
                    String date = mStartYear + "年" + mStartMonth + "月" + mStartDay + "日";
                    String time = String.format("  %02d:%02d",mStartHour,mStartMinute);
                    mEventActiviteTime = date + time;
                    mTvEventTime.setText(mEventActiviteTime);

                    if (mEventType.equals("9")){
                        mEndYear = mStartYear;
                        mEndMonth = mStartMonth;
                        if (mStartHour == 23) {
                            mEndDay = mStartDay + 1;
                            mEndHour = 0;
                        } else {
                            mEndDay = mStartDay;
                            mEndHour = hour.getCurrentItem() + 1;
                        }
                        mEndMinute = mins.getCurrentItem() * 5;
                        c.set(mEndYear, mEndMonth - 1, mEndDay, mEndHour, mEndMinute, 00);
                        mEndTime = c.getTimeInMillis();
                        String endTime = String.format("  %02d:%02d",mEndHour,mEndMinute);
                        mTvEndTime.setText(endTime);
                    }

                } else {
                    Toast.makeText(CreateNewEventActivity.this, "时间过时了，请重新选择", Toast.LENGTH_LONG).show();
                    mStartTime = 0l;
                    mTvEventTime.setText("");
                }

                mDateSelectPop.dismiss();
            }
        });
        TextView cancel = (TextView) view.findViewById(R.id.new_cancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDateSelectPop.dismiss();
            }
        });

        mDateSelectPop = new PopupWindow(this);
        mDateSelectPop.setBackgroundDrawable(new BitmapDrawable());
        mDateSelectPop.setFocusable(true);
        mDateSelectPop.setTouchable(true);
        mDateSelectPop.setOutsideTouchable(true);
        mDateSelectPop.setContentView(view);
        mDateSelectPop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        mDateSelectPop.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        mDateSelectPop.setAnimationStyle(R.style.bottomStyle);
        mDateSelectPop.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        mDateSelectPop.update();
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                mDateSelectPop.dismiss();
                return false;
            }
        });
    }

    /**
     * 快速显示结束时间
     * 持续时间
     * 选择其他弹出结束时间选择框
     */
    public void showContinueDateSelectPop() {
        final View view = LayoutInflater.from(this).inflate(R.layout.continue_time_pop_layout, null);
        TextView continueTime1 = (TextView) view.findViewById(R.id.continue_time1);
        TextView continueTime2 = (TextView) view.findViewById(R.id.continue_time2);
        TextView continueTime3 = (TextView) view.findViewById(R.id.continue_time3);
        TextView continueTime4 = (TextView) view.findViewById(R.id.continue_time4);
        TextView continueTimeOther = (TextView) view.findViewById(R.id.continue_time_other);
        TextView continueTimeCancle = (TextView) view.findViewById(R.id.continue_time_cancle);
        continueTime1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mEndTime = mStartTime + 30 * 60 * 1000;
                setEndTime();
                mTimeContinuePop.dismiss();
            }
        });
        continueTime2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mEndTime = mStartTime + 60 * 60 * 1000;
                setEndTime();
                mTimeContinuePop.dismiss();
            }
        });

        continueTime3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mEndTime = mStartTime + 120 * 60 * 1000;
                setEndTime();
                mTimeContinuePop.dismiss();
            }
        });
        continueTime4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mEndTime = mStartTime + 180 * 60 * 1000;
                setEndTime();
                mTimeContinuePop.dismiss();
            }
        });

        continueTimeOther.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                showEndDateSelectPop();
                mTimeContinuePop.dismiss();
            }
        });

        continueTimeCancle.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mTimeContinuePop.dismiss();
            }
        });


        mTimeContinuePop = new PopupWindow(this);
        mTimeContinuePop.setBackgroundDrawable(new BitmapDrawable());
        mTimeContinuePop.setFocusable(true);
        mTimeContinuePop.setTouchable(true);
        mTimeContinuePop.setOutsideTouchable(true);
        mTimeContinuePop.setContentView(view);
        mTimeContinuePop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        mTimeContinuePop.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        mTimeContinuePop.setAnimationStyle(R.style.bottomStyle);
        mTimeContinuePop.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        mTimeContinuePop.update();
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                mTimeContinuePop.dismiss();
                return false;
            }
        });
    }


    private void setEndTime() {
        mEndYear = DateUtil.getYear(mEndTime);
        mEndMonth = DateUtil.getMonth(mEndTime);
        mEndDay = DateUtil.getDay(mEndTime);
        mEndHour = DateUtil.getHour(mEndTime);
        mEndMinute = DateUtil.getMinute(mEndTime);
        mTvEndTime.setText(DateUtil.getHourAndMin(mEndTime));
    }


    private boolean isOverTime() {
        long curTime = System.currentTimeMillis();
        // 注意月份的加减
        c.set(mStartYear, mStartMonth - 1, mStartDay, mStartHour, mStartMinute, 00);
        long selectTime = c.getTimeInMillis();

        if (selectTime > curTime) {
            mStartTime = selectTime;
            return true;
        } else {
            return false;
        }

    }


    /**
     * 选择日期时间 pop
     */
    public void showEndDateSelectPop() {
        final View view = LayoutInflater.from(this).inflate(R.layout.select_time_pop_layout, null);
        hour = (WheelView) view.findViewById(R.id.new_hour);
        initHour();
        mins = (WheelView) view.findViewById(R.id.new_mins);
        initMins();
        // 设置当前时间
//        hour.setCurrentItem(curHour);
//        mins.setCurrentItem(curMinute);
        if (mEndHour != 0) {
            hour.setCurrentItem(mEndHour);
        } else {
            hour.setCurrentItem(curHour);
        }
        if (mEndMinute != 0) {
            mins.setCurrentItem(mEndMinute / 5);
        } else {
            mins.setCurrentItem(curMinute / 5);
        }

        TextView bt = (TextView) view.findViewById(R.id.new_set);
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mEndHour = hour.getCurrentItem();
                mEndMinute = mins.getCurrentItem() * 5;
                if (mEndHour < mStartHour || (mEndHour == mStartHour && mEndMinute < mStartMinute)) {
                    Toast.makeText(CreateNewEventActivity.this, "结束时间小于开始时间，请重新选择", Toast.LENGTH_LONG).show();
                    mEndHour = 0;
                    mEndMinute = 0;
                    mEndTime = 0;
                    mTvEndTime.setText("");
                } else {
                    mEventEndTime = String.format("  %02d:%02d",mEndHour,mEndMinute);
                    mTvEndTime.setText(mEventEndTime);
                }
                mDateSelectPop.dismiss();
            }
        });
        TextView cancel = (TextView) view.findViewById(R.id.new_cancel);
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mDateSelectPop.dismiss();
            }
        });

        mDateSelectPop = new PopupWindow(this);
        mDateSelectPop.setBackgroundDrawable(new BitmapDrawable());
        mDateSelectPop.setFocusable(true);
        mDateSelectPop.setTouchable(true);
        mDateSelectPop.setOutsideTouchable(true);
        mDateSelectPop.setContentView(view);
        mDateSelectPop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        mDateSelectPop.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        mDateSelectPop.setAnimationStyle(R.style.bottomStyle);
        mDateSelectPop.showAtLocation(view, Gravity.BOTTOM, 0, 0);
        mDateSelectPop.update();
        view.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                mDateSelectPop.dismiss();
                return false;
            }
        });
    }

    /**
     * 当年份和月份滑动结束，更新天数
     */
    OnWheelScrollListener scrollListener = new OnWheelScrollListener() {

        @Override
        public void onScrollingStarted(WheelView wheel) {

        }

        @Override
        public void onScrollingFinished(WheelView wheel) {
            // TODO Auto-generated method stub
            // int n_year = year.getCurrentItem() + 2015;// 楠烇拷
            int n_year = curYear;
            int n_month = month.getCurrentItem() + 1;// 閺堬拷
            initDay(n_year, n_month);
        }
    };

    /**
     * @param year
     * @param month
     * @return
     */
    private int getDay(int year, int month) {
        int day = 30;
        boolean flag = false;
        switch (year % 4) {
            case 0:
                flag = true;
                break;
            default:
                flag = false;
                break;
        }
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                day = 31;
                break;
            case 2:
                day = flag ? 29 : 28;
                break;
            default:
                day = 30;
                break;
        }
        return day;
    }

    /**
     * 初始化年
     */
    private void initYear(int curYear) {
        NumericWheelAdapter numericWheelAdapter = new NumericWheelAdapter(this, curYear, curYear + 1);
        numericWheelAdapter.setLabel(" 年");
        //		numericWheelAdapter.setTextSize(15);  设置字体大小
        year.setViewAdapter(numericWheelAdapter);
        year.setCyclic(false);
    }

    /**
     * 初始化月
     */
    private void initMonth() {
        NumericWheelAdapter numericWheelAdapter = new NumericWheelAdapter(this, 1, 12, "%02d");
        numericWheelAdapter.setLabel(" 月");
        //		numericWheelAdapter.setTextSize(15);  设置字体大小
        month.setViewAdapter(numericWheelAdapter);
        month.setCyclic(true);
        month.addScrollingListener(scrollListener);
    }

    /**
     * 初始化天
     */
    private void initDay(int arg1, int arg2) {
        int count = getDay(arg1, arg2);
        NumericWheelAdapter numericWheelAdapter = new NumericWheelAdapter(this, 1, count, "%02d");
        numericWheelAdapter.setLabel(" 日");
        //		numericWheelAdapter.setTextSize(15);  设置字体大小
        day.setViewAdapter(numericWheelAdapter);
        day.setCyclic(true);
        // TODO 如果之前选择的日期大于这个月的天数 置为第一天
        if (day.getCurrentItem() + 1 > count) {
            day.setCurrentItem(0);
        }
    }

    /**
     * 初始化时
     */
    private void initHour() {
        NumericWheelAdapter numericWheelAdapter = new NumericWheelAdapter(this, 0, 23, "%02d");
        numericWheelAdapter.setLabel(" 时");
        //		numericWheelAdapter.setTextSize(15);  设置字体大小
        hour.setViewAdapter(numericWheelAdapter);
        hour.setCyclic(true);
    }

    /**
     * 初始化分
     */
    private void initMins() {
        NumericWheelAdapter numericWheelAdapter = new NumericWheelAdapter(this, 0, 11, "%02d", 5);
        numericWheelAdapter.setLabel(" 分");
//		numericWheelAdapter.setTextSize(15);  设置字体大小
        mins.setViewAdapter(numericWheelAdapter);
        mins.setCyclic(true);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case Constants.SELECT_IMG_BACK:
                if (resultCode == RESULT_OK) {
                    setImageMsg();
                } else if (resultCode == 100) {
                    String imgPath = data.getStringExtra(Constants.IMAGE_PATH);
                    Bimp.tempSelectBitmap.add(imgPath);
                    setImageMsg();
                }
                break;
            case PhotoUtil.CAMERA_WITH_DATAA:

                if (Bimp.tempSelectBitmap.size() < 9 && resultCode == RESULT_OK) {
                    Bitmap bitmap = PhotoUtil.readBitmapFromPath(this, mFilePath, false);
                    int degree = PhotoUtil.getExifOrientation(mFilePath);
                    if (degree != 0) {
                        bitmap = PhotoUtil.rotaingImageView(bitmap, degree);
                        FileUtils.deleteFolderFile(mFilePath, true);
                        mFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Yun/Images/" + PhotoUtil.saveBitmaptoSdCard(bitmap, "/Yun/Images");
                    }
                    Bimp.tempSelectBitmap.add(mFilePath);
                    setImageMsg();
                }
                break;
            case VOTE_NUMBER:
                if (resultCode == RESULT_OK){
                    int number = data.getIntExtra("number",0);
                    if (number > 0){
                        mMaxVoteNumber = number;
                        mTvVoteNumber.setText("最多选" + mMaxVoteNumber + "项");
                    }
                }
                break;
        }

    }

    private void setImageMsg() {
        int imgSize = 0;
        if (Bimp.tempSelectBitmap != null) {
            imgSize = Bimp.tempSelectBitmap.size();
            if (imgSize > 0) {
                mImageHScrollView.setVisibility(View.VISIBLE);
                mImageHLinearLayout.removeAllViews();
                for (int i = 0; i < Bimp.tempSelectBitmap.size(); i++) {
                    final String image = Bimp.tempSelectBitmap.get(i);
                    final int position = i;
                    final View view = LayoutInflater.from(CreateNewEventActivity.this).inflate(R.layout.ho_list_item, mImageHLinearLayout, false);
                    ImageView mIvDelete = (ImageView) view.findViewById(R.id.event_iv_item_delete);
                    ImageView mIvImage = (ImageView) view.findViewById(R.id.event_iv_item_image);
                    ImageLoader.getInstance().displayImage("file://" + image, mIvImage, ImageLoaderInterface.optionEventImage);

                    mIvDelete.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            Bimp.deletePhoto(image);
                            Bimp.tempSelectBitmap.remove(image);
                            mImageHLinearLayout.removeView(view);
                            if (Bimp.tempSelectBitmap.size() <= 0) {
                                showImageLayout(false);
                            } else {
                                showImageLayout(true);
                            }
                        }
                    });
                    mIvImage.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent intent = new Intent(CreateNewEventActivity.this, ImagePagerActivity.class);
                            intent.putExtra(Constants.IMAGE_ORIGIN, Constants.IMAGE_ORIGIN_LOCAL_ARRAY);
                            intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_URLS, Bimp.tempSelectBitmap);
                            intent.putExtra(ImagePagerActivity.EXTRA_IMAGE_INDEX, position);
                            startActivity(intent);
                        }
                    });
                    mImageHLinearLayout.addView(view);
                }
            } else {
                mImageHScrollView.setVisibility(View.GONE);
            }

        }


    }

    /**
     * 显示等待的dialog
     */
    private void httpReqDlgShow() {
        if (mWaitDialog == null) {
            mWaitDialog = AllDialogUtil.getInstance(mActivity).waitDialog();
//            mProgressDialog.setCancelable(false);
            if (!mWaitDialog.isShowing()) {
                mWaitDialog.show();
            }
        }

    }

    /**
     * 取消等待的dialog
     */
    private void httpReqDlgDismiss() {
        if (mWaitDialog != null && mWaitDialog.isShowing()) {
            mWaitDialog.dismiss();
            mWaitDialog = null;
        }
    }


    @Override
    public void addImage() {
        Intent intent1 = new Intent(CreateNewEventActivity.this, ChooseContactByTeamActivity.class);
        intent1.setAction("events_add_receiver");
        Bundle bundle = new Bundle();

        EventListData eventData = new EventListData();
        eventData.setEventType(mEventType);
        eventData.setEventName(mTvTitle.getText().toString().trim());
        if (mReceiverMsg == null) {
            eventData.setReceiver("");
        } else {
            eventData.setReceiver(mReceiverMsg);
        }
        eventData.setEventTitle(mCreateEventTheme.getText().toString().trim());
        eventData.setContent1(mEventPart1.getText().toString().trim());
        eventData.setContent2(mEventPart1.getText().toString().trim());
        eventData.setContent3(mEventPart1.getText().toString().trim());
        eventData.setInitTitle1(mHintPart1);
        eventData.setAuthor(mEventAuthor.getText().toString().trim());
        eventData.setActivityTime(mStartTime + "");
        eventData.setVoteMaxNumber(mMaxVoteNumber + "");

        c.set(curYear, mStartMonth - 1, mStartDay, mEndHour, mEndMinute, 00);
        mEndTime = c.getTimeInMillis();
        eventData.setEndTime(mEndTime + "");

        eventData.setIsQrcode(getNotice());
        eventData.setActivitySite(mEventAddress.getText().toString());
        if ("8".equals(mEventType)) {
            eventData.setContent1(getPassVoteData());
        }
        bundle.putSerializable("event_bundle", eventData);
        intent1.putExtra("event_msg", bundle);

        startActivity(intent1);
    }

    @Override
    public void delImage(int position) {
        ArrayList<HashMap<String, Object>> list = new ArrayList<HashMap<String, Object>>();
        StringBuilder sb = new StringBuilder();
        try {
            JSONArray jsonArray = new JSONArray(mReceiverMsg);
            JSONArray newJsonArray = new JSONArray();
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                if (!jsonObject.get("user_id").equals((String) mEventReceiverGrid.getData().get(position).get("user_id"))) {
                    HashMap<String, Object> map = new HashMap<String, Object>();
                    newJsonArray.put(jsonObject);
                    sb.append(jsonObject.get("user_name") + ",");
                    map.put("text", jsonObject.get("user_name"));
                    map.put("icon", jsonObject.get("user_image").toString());
                    map.put("user_id", jsonObject.getString("user_id"));
                    map.put("contact_id", jsonObject.get("contact_id"));
                    list.add(map);
                } else if ("0".equals(jsonObject.get("user_id"))) {
                    if (!jsonObject.get("user_name").equals((String) mEventReceiverGrid.getData().get(position).get("text"))) {
                        HashMap<String, Object> map = new HashMap<String, Object>();
                        newJsonArray.put(jsonObject);
                        sb.append(jsonObject.get("user_name") + ",");
                        map.put("text", jsonObject.get("user_name"));
                        map.put("icon", jsonObject.get("user_image").toString());
                        map.put("user_id", jsonObject.getString("user_id"));
                        map.put("contact_id", jsonObject.get("contact_id"));
                        list.add(map);
                    }
                }
            }
            if (sb.length() > 0) {
                mCreateEventReceiverName.setText(sb.substring(0, sb.length() - 1));
                mCreateEventAddReceiverArrow.setVisibility(View.VISIBLE);
                mCreateEventAddReceiver.setVisibility(View.GONE);
            } else {
                mCreateEventReceiverName.setText("");
                mCreateEventAddReceiverArrow.setVisibility(View.GONE);
                mCreateEventAddReceiver.setVisibility(View.VISIBLE);
            }
            mReceiverMsg = newJsonArray.toString();
            adapter = new ImageAdapter(CreateNewEventActivity.this, true);
            mEventReceiverGrid.initData(false, list, adapter);
            mEventReceiverGrid.setHandleGridView(CreateNewEventActivity.this);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void queryImage(int position) {

    }


    /**
     * 新建事件和新公告
     */
    public void createNewEvent() {
        JSONArray array;
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin
                .getInstance().mSid));

        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_TYPE, mEventType));

        JSONObject content1 = new JSONObject();
        try {
            content1.put(AsynHttpClient.KEY_EVENT_INIT_TITLE, mHintPart1);
            content1.put(AsynHttpClient.KEY_EVENT_INIT_CONTENT, mEventPart1.getText().toString());
        } catch (JSONException e) {
            e.printStackTrace();
        }

        array = new JSONArray();
        array.put(content1);

        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_MEMBERS, mReceiverMsg));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_TITLE, mCreateEventTheme.getText().toString()));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_CONTENT, array.toString()));
        if (imageArray != null && imageArray.length() > 0) {
            nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_ATTACHMENT, imageArray.toString()));
        } else {
            nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_ATTACHMENT, ""));
        }
        String eventTypeName = mTvTitle.getText().toString().replace("发", "");
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_NAME, eventTypeName));
        if (mEventType.equals("1")) {
            nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_AUTHOR, mEventAuthor.getText().toString()));
        }
        CreateEventMsg createEventMsg = new CreateEventMsg(mHandler.obtainMessage(CREATE_NEW_EVENT), this, mEventType, eventTypeName, mEventAvatar);
        createEventMsg.mApi = AsynHttpClient.API_EVENT_ADD;
        createEventMsg.mParams = nvps;
        AsynHttpClient.getInstance(this).execEventHttp(createEventMsg);

    }

    /**
     * 创建新活动
     */
    public void createNewActive() {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin
                .getInstance().mSid));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_TYPE, "7"));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_MEMBERS, mReceiverMsg));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_TITLE, mCreateEventTheme.getText().toString()));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_ACTIVITE_TIME, "" + mStartTime / 1000));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_ACTIVITE_ADDRESS, mEventAddress.getText().toString()));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_CONTENT, mEventPart1.getText().toString()));
        if (imageArray != null && imageArray.length() > 0) {
            nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_ATTACHMENT, imageArray.toString()));
        }
        CreateEventMsg createEventMsg = new CreateEventMsg(mHandler.obtainMessage(CREATE_NEW_EVENT), this, mEventType, "", mEventAvatar);
        createEventMsg.mApi = AsynHttpClient.API_EVENT_ADD_ACTIVE;
        createEventMsg.mParams = nvps;
        AsynHttpClient.getInstance(this).execEventHttp(createEventMsg);

    }

    /**
     * 创建新投票
     */
    public void createNewVote(ArrayList<String> data) {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin
                .getInstance().mSid));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_TYPE, "8"));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_MEMBERS, mReceiverMsg));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_TITLE, mCreateEventTheme.getText().toString()));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_VOTE_NUMBER, mMaxVoteNumber + ""));
        JSONArray array = new JSONArray();
        for (int i = 0; i < data.size(); i++) {
            JSONObject object = new JSONObject();
            try {
                object.put(AsynHttpClient.KEY_EVENT_INIT_TITLE, (char) (65 + i) + "");
                object.put(AsynHttpClient.KEY_EVENT_INIT_CONTENT, data.get(i));
                array.put(object);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_CONTENT, array.toString()));
        if (imageArray != null && imageArray.length() > 0) {
            nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_ATTACHMENT, imageArray.toString()));
        }
        CreateEventMsg createEventMsg = new CreateEventMsg(mHandler.obtainMessage(CREATE_NEW_EVENT), this, mEventType, "", mEventAvatar);
        createEventMsg.mApi = AsynHttpClient.API_EVENT_ADD_VOTE;
        createEventMsg.mParams = nvps;
        AsynHttpClient.getInstance(this).execEventHttp(createEventMsg);
    }

    /**
     * 创建新会议签到
     */
    public void createNewReg() {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin
                .getInstance().mSid));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_TYPE, "9"));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_MEMBERS, mReceiverMsg));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_TITLE, mCreateEventTheme.getText().toString()));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_START_TIME, "" + mStartTime / 1000));
        if (DateUtil.getHour(mEndTime) == 0 && DateUtil.getMinute(mEndTime) == 0) {
            nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_DATE_TIME, "0"));
        } else {
            nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_DATE_TIME, "" + mEndTime / 1000));
        }
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_IS_QRCODE, getNotice()));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_ADDRESS, mEventAddress.getText().toString()));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_EVENT_CONTENT, mEventPart1.getText().toString()));
        CreateEventMsg createEventMsg = new CreateEventMsg(mHandler.obtainMessage(CREATE_NEW_EVENT), this, mEventType, "", mEventAvatar);
        createEventMsg.mApi = AsynHttpClient.API_EVENT_CALENDAR_ADD_METTING;
        createEventMsg.mParams = nvps;
        AsynHttpClient.getInstance(this).execEventHttp(createEventMsg);
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        switch (keyCode) {
            case KeyEvent.KEYCODE_BACK:
                if (mEventReceiverLayout.getVisibility() == View.VISIBLE) {
                    mCreateEventTitle.setVisibility(View.VISIBLE);
                    mEventReceiverLayout.setVisibility(View.GONE);
                    mCreateEventLayout.setVisibility(View.VISIBLE);
                    return true;
                } else {
                    try {
                        ((InputMethodManager) getSystemService(INPUT_METHOD_SERVICE)).hideSoftInputFromWindow(CreateNewEventActivity.this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    StringBuilder stringBuilder = new StringBuilder();
                    if (mCreateEventReceiverName.getText().toString().length() > 0 || mCreateEventTheme.getText().toString().length() > 0 || mEventPart1.getText().toString().length() > 0 || mTvEventTime.getText().toString().length() > 0 || mEventAddress.getText().toString().length() > 0 || mEventAuthor.getText().toString().length() > 0 || Bimp.tempSelectBitmap.size() > 0) {
                        if (Bimp.tempSelectBitmap != null && Bimp.tempSelectBitmap.size() > 0) {
                            for (String image : Bimp.tempSelectBitmap) {
                                stringBuilder.append(image + ",");
                            }
                            images = stringBuilder.toString();
                        } else {
                            images = "";
                        }
                        showSavePop();
                    } else {
                        Bimp.deleteAllPhoto();
                        finish();
                    }
                }
                break;
        }
        return super.onKeyDown(keyCode, event);
    }

    public void getQnToken(String keys) {
        List<NameValuePair> mList = new ArrayList<NameValuePair>();
        mList.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin.getInstance().mSid));
        mList.add(new BasicNameValuePair(AsynHttpClient.KEY_KEY, keys));
        GetQnTokenMsg getQnTokenMsg = new GetQnTokenMsg(mHandler.obtainMessage(GET_QN_TOKEN));
        getQnTokenMsg.mApi = AsynHttpClient.API_QN_GET_EVENT_TOKEN;
        getQnTokenMsg.mParams = mList;
        AsynHttpClient.getInstance(this).execUserHttp(getQnTokenMsg);
    }

    //设置图片
    public void setPhoto(String token, byte[] file, String fileName) {
        Log.d("七牛--token", token);
        Log.d("七牛--fileName", fileName);
        DialerApp.getUploadManager(this).put(file, fileName, token,
                new UpCompletionHandler() {
                    @Override
                    public void complete(String key, ResponseInfo info, JSONObject response) {
                        Log.d("七牛--info.isOk()", info.isOK() + "--response" + response);
                        ++mImageCount;
                        if (imageArray.length() == mImageCount) {
                            mHandler.postDelayed(new Runnable() {
                                @Override
                                public void run() {
                                    Bimp.deleteAllPhotoAfterSend();
                                    Constants.NEW_EVENT_ID = "";
                                }
                            }, 3000);

                        }
                    }
                }, null);
    }

    @Override
    public void onUpdateAdd(int i) {
        if (mVoteData.size() >= 10) {
            Toast.makeText(this, "最多10个选项", Toast.LENGTH_SHORT).show();
        } else {
            getVoteData();
            mVoteData.add("");
            mVoteAdapter.notifyDataSetChanged();
        }
    }

    @Override
    public void onUpdateRemove(int i) {
        getVoteData();
        mVoteData.remove(i);
        mVoteAdapter.notifyDataSetChanged();
    }

    /**
     * 获取投票各选项内容
     *
     * @return
     */
    public String getPassVoteData() {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < mVoteList.getChildCount(); i++) {
            LinearLayout layout = (LinearLayout) mVoteList.getChildAt(i);// 获得子item的layout
            EditText et = (EditText) layout.getChildAt(0).findViewById(R.id.vote_item_et_content);// 从layout中获得控件,根据其id
            // EditText et = (EditText) layout.getChildAt(1)//或者根据位置,在这我假设TextView在前，EditText在后
            sb.append(et.getText().toString().trim()).append(",");
        }
        return sb.toString().substring(0, sb.length() - 1);
    }

    /**
     * 获取投票各选项内容
     *
     * @
     */
    public void getVoteData() {
        mVoteData.clear();
        for (int i = 0; i < mVoteList.getChildCount(); i++) {
            LinearLayout layout = (LinearLayout) mVoteList.getChildAt(i);// 获得子item的layout
            EditText et = (EditText) layout.getChildAt(0).findViewById(R.id.vote_item_et_content);// 从layout中获得控件,根据其id
            // EditText et = (EditText) layout.getChildAt(1)//或者根据位置,在这我假设TextView在前，EditText在后
            mVoteData.add(et.getText().toString().trim());
        }
    }

    /**
     * 显示选择图片的 HScrollView
     *
     * @param flag true：显示  false：不显示
     */
    public void showImageLayout(boolean flag) {
        if (flag) {
            mImageHScrollView.setVisibility(View.VISIBLE);
        } else {
            mImageHScrollView.setVisibility(View.GONE);
        }
    }


    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        // 检测屏幕的方向：纵向或横向
        if (this.getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_LANDSCAPE) {
            //当前为横屏， 在此处添加额外的处理代码
            Log.d("InstanceState", "--InstanceState  ==  heng ping " );

        } else if (this.getResources().getConfiguration().orientation
                == Configuration.ORIENTATION_PORTRAIT) {
            //当前为竖屏， 在此处添加额外的处理代码
            Log.d("InstanceState", "--InstanceState  ==  shu ping ");
        }
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        outState.putString("pic_path", mFilePath);
        outState.putLong("start_time", mStartTime);
        outState.putLong("end_time", mEndTime);
        outState.putString("start_time_date", mEventActiviteTime);
        outState.putString("end_time_date", mEventEndTime);
        outState.putStringArrayList("images",Bimp.tempSelectBitmap);
        super.onSaveInstanceState(outState);
    }

    @Override
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        mFilePath = savedInstanceState.getString("pic_path");
        mStartTime = savedInstanceState.getLong("start_time");
        mEndTime = savedInstanceState.getLong("end_time");
        mEventActiviteTime = savedInstanceState.getString("start_time_date");
        mEventEndTime = savedInstanceState.getString("end_time_date");

        if (!StringUtil.isEmpty(mEventActiviteTime)){
            mTvEventTime.setText(mEventActiviteTime);
        }
        if (!StringUtil.isEmpty(mEventEndTime)){
            mTvEndTime.setText("mEventEndTime");
        }
        ArrayList<String> images = savedInstanceState.getStringArrayList("images");
        if (images != null && images.size() > 0){
            Bimp.tempSelectBitmap.clear();
            Bimp.tempSelectBitmap.addAll(savedInstanceState.getStringArrayList("images"));
        }
        LocalLogin.getInstance().login(this);
        super.onRestoreInstanceState(savedInstanceState);
        Log.d("InstanceState", "--onRestoreInstanceState  ==  " + KPSwitchConflictUtil.mFlag);
    }
}
